package Leetcode;

import tree.TreeNode;

public class isSymmetric {
    public boolean isSymmetric(TreeNode root) {
        if (root == null){
            return true;
        }
        return is(root.left, root.right);
    }
    public boolean is(TreeNode left, TreeNode right){
        if (left == null && right != null){
            return false;
        }
        if (left != null && right == null){
            return false;
        }
        if (left == null){
            return true;
        }
        if (left.val != right.val){
            return false;
        }
        boolean out = is(left.left, right.right);
        boolean in = is(left.right, right.left);
        return out && in;
    }
}
